/**
 * GeneratorFactory.java
 * 2012-2-28 下午01:12:19
 */
package xgenerator.factory;

import java.io.IOException;

import xgenerator.constants.AppFrameworks;
import xgenerator.constants.PersistenceFrameworks;
import xgenerator.constants.RiaTypes;
import xgenerator.constants.ViewTypes;
import xgenerator.constants.WebFrameworks;
import xgenerator.generators.Generator;
import xgenerator.generators.jgenerator.impl.AppFrame52Generator;
import xgenerator.generators.jgenerator.impl.Struts13Spring256Hibernate36JspExt3Generator;
import xgenerator.generators.jgenerator.impl.Struts13Spring256Hibernate36JspGenerator;
import xgenerator.generators.jgenerator.impl.Struts23Spring256Hibernate36JspExt4Generator;
import xgenerator.generators.jgenerator.impl.Struts23Spring256Hibernate36JspGenerator;
import xgenerator.model.ModelMetadata;
import xgenerator.util.StringUtils;

/**
 * <p>
 * Title:类的中文名
 * </p>
 * <p>
 * Description:具体功能见各方法描述
 * </p>
 * <p>
 * Copyright:Copyright (c) 2012
 * </p>
 * 
 * @author <a href="mailto:lishushan@gmail.com">liss</a>
 * @version 1.0
 */
public final class GeneratorFactory {
	
	/**
	 * <p>
	 * Title：代码生成器工厂方法
	 * </p>
	 * @param modelMetadata
	 * @return
	 * @throws IOException
	 */
	public static final Generator getGenerator(ModelMetadata modelMetadata) {
		if(ViewTypes.JSP.equals(modelMetadata.getView()) && WebFrameworks.APPFRAME_5_2.equals(modelMetadata.getWebFramework()) && StringUtils.isBlank(modelMetadata.getAppFramework()) && StringUtils.isBlank(modelMetadata.getPersistenceFramework()) && StringUtils.isBlank(modelMetadata.getRia())) {
			return new AppFrame52Generator();
		} else if(ViewTypes.JSP.equals(modelMetadata.getView()) && WebFrameworks.STRUTS_1_3_10_FRAMEWORK.equals(modelMetadata.getWebFramework()) && AppFrameworks.SPRING_2_5_6_FRAMEWORK.equals(modelMetadata.getAppFramework()) && PersistenceFrameworks.HIBERNATE_3_6_10_FRAMEWORK.equals(modelMetadata.getPersistenceFramework()) && RiaTypes.EXTJS_3_PRESENTATION.equals(modelMetadata.getRia())) {
			return new Struts13Spring256Hibernate36JspExt3Generator();
		} else if(ViewTypes.JSP.equals(modelMetadata.getView()) && WebFrameworks.STRUTS_1_3_10_FRAMEWORK.equals(modelMetadata.getWebFramework()) && AppFrameworks.SPRING_2_5_6_FRAMEWORK.equals(modelMetadata.getAppFramework()) && PersistenceFrameworks.HIBERNATE_3_6_10_FRAMEWORK.equals(modelMetadata.getPersistenceFramework()) && StringUtils.isBlank(modelMetadata.getRia())) {
			return new Struts13Spring256Hibernate36JspGenerator();
		} else if(ViewTypes.JSP.equals(modelMetadata.getView()) && WebFrameworks.STRUTS_2_3_x_FRAMEWORK.equals(modelMetadata.getWebFramework()) && AppFrameworks.SPRING_2_5_6_FRAMEWORK.equals(modelMetadata.getAppFramework()) && PersistenceFrameworks.HIBERNATE_3_6_10_FRAMEWORK.equals(modelMetadata.getPersistenceFramework()) && RiaTypes.EXTJS_4_PRESENTATION.equals(modelMetadata.getRia())) {
			return new Struts23Spring256Hibernate36JspExt4Generator();
		} else if(ViewTypes.JSP.equals(modelMetadata.getView()) && WebFrameworks.STRUTS_2_3_x_FRAMEWORK.equals(modelMetadata.getWebFramework()) && AppFrameworks.SPRING_2_5_6_FRAMEWORK.equals(modelMetadata.getAppFramework()) && PersistenceFrameworks.HIBERNATE_3_6_10_FRAMEWORK.equals(modelMetadata.getPersistenceFramework()) && StringUtils.isBlank(modelMetadata.getRia())) {
			return new Struts23Spring256Hibernate36JspGenerator();
		}
		
		throw new RuntimeException("找不到该框架组合对应的代码生成器！");
	}

}
